<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('员工假期列表')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>员工姓名：</label>
                                <input type="text" name="empName"/>
                            </li>
                            <div th:include="include/deptSearch::deptSearch"></div>
                            <li>
                                <label>岗位：</label>
                                <select id="postId" class="form-control m-b" name="postId" th:with="postAll=${@postService.getPostAll()}">
                                    <option value="">所有</option>
                                    <option th:each="post : ${postAll}" th:text="${post.getPostName()}" th:value="${post.getPostId()}"  th:hidden="${post.getStatus() == '1'}"></option>
                                </select>
                            </li>

                            <li>
                                <label>假期类型：</label>
                                <select name="type" th:with="type=${@dict.getType('biz_leave_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>

                            <li class="select-time">
                                <label>开始日期：</label>
                                <input type="text" class="time-input" placeholder="开始时间" name="startDate"/>
                            </li>
                            <li class="select-time">
                                <label>结束日期：</label>
                                <input type="text" class="time-input" placeholder="结束时间" name="endDate"/>
                            </li>

                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="hr:holiday:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="hr:holiday:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="hr:holiday:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>

                <a class="btn btn-info" onclick="init()" shiro:hasPermission="hr:holiday:add">
                    <i class="fa fa-download"></i> 初始化年假
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="hr:holiday:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <div th:replace="include/importUtil::importUtil('/hr/holiday/downloadTemplate','/hr/holiday/importData','/hr/holiday/checkUrl','/hr/holiday/exportErrorList','/hr/holiday/exportError')"
                     shiro:hasPermission="hr:holiday:export" ></div>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>

    <th:block th:include="include :: footer" />
     <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('hr:holiday:edit')}]];
        var removeFlag = [[${@permission.hasPermi('hr:holiday:remove')}]];
        var prefix = ctx + "hr/holiday";

        var holidayType = [[${@dict.getType('biz_leave_type')}]];

        /*var deptIdMap = {};
        $('#deptId option').each(function(i, n){
            deptIdMap[$(n).val()] = $(n).text();
        });

        var postIdsMap = {};
        $('#postId option').each(function(i, n){
            postIdsMap[$(n).val()] = $(n).text();
        });*/

        function reset(){
                debugger
                $('#postId').val("").select2();


            $.form.reset();
        }

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "员工假期",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id', 
                    title: 'id',
                    visible: false
                },
                {
                    field: 'empId', 
                    title: '员工id',
                    visible: false
                },
                {
                    field: 'empName',
                    title: '员工姓名'
                },
                {
                    field: 'userId', 
                    title: '用户id',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '所属部门'

                },
                {
                    field: 'postName',
                    title: '岗位'
                },
                {
                    field: 'type', 
                    title: '假期类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(holidayType, value);
                    }
                },
                {
                    field: 'hours', 
                    title: '假期时长/小时'
                },
                {
                    field: 'useHours', 
                    title: '已用假期时长/小时'
                },
                {
                    field: 'startDate', 
                    title: '开始日期'
                },
                {
                    field: 'endDate', 
                    title: '结束日期'
                },
                {
                    title: '可用时长',
                    formatter: function(value, row, index) {
                        return (row.hours - row.useHours).toFixed(1);
                    }
                },
                {
                    field: 'source', 
                    title: '来源',
                    visible: false
                },
                {
                    field: 'remark', 
                    title: '备注',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

         function init() {
             let initUrl = prefix + "/init";
             open("初始化年假配置" ,  initUrl, 500,300);
        }

        // 弹出层指定宽度
        function open(title, url, width, height, callback,callbackEnd) {

            //如果是移动端，就使用自适应大小弹窗
            if ($.common.isMobile()) {
                width = 'auto';
                height = 'auto';
            }
            if ($.common.isEmpty(title)) {
                title = false;
            }
            if ($.common.isEmpty(url)) {
                url = "/404.html";
            }
            if ($.common.isEmpty(width)) {
                width = 800;
            }
            if ($.common.isEmpty(height)) {
                height = ($(window).height() - 50);
            }
            if ($.common.isEmpty(callback)) {
                callback = function(index, layero) {
                    var iframeWin = layero.find('iframe')[0];
                    iframeWin.contentWindow.submitHandler(index, layero);
                }
            }
            layer.open({
                type: 2,
                area: [width + 'px', height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: title,
                content: url,
                btn: ['初始化年假', '关闭'],
                // 弹层外区域关闭
                shadeClose: false,
                yes: callback,
                end: function() {
                    if (!$.common.isEmpty(callbackEnd)) {
                        if (typeof callbackEnd == "function") {
                            callbackEnd();
                        }
                    }
                },
                cancel: function(index) {
                    return true;
                }
            });
        }



    </script>
</body>
</html>